/*
玩家信息界面逻辑处理，在大厅的时候只需要initPart1，在游戏场景中要initPart2添加额外的功能
*/
var confige = require("confige");
var gameData = require("gameData");

cc.Class({
    extends: cc.Component,

    properties: {
        parent:{
            default:null,
            type:cc.Node
        },
        isInit:false,
    },

    onLoad: function () {

    },

    onInit:function(init2){
        this.initPart1();
        if(init2)
            this.initPart2();

        this.selectHead = -1;
        this.isInit = true;
    },

    initPart1:function(){
        this.userNode = this.node.getChildByName("userNode");
        this.head = this.userNode.getChildByName("head").getComponent("cc.Sprite");
        this.nickName = this.userNode.getChildByName("nickName").getComponent("cc.Label");//昵称：XXX
        this.id = this.userNode.getChildByName("id").getComponent("cc.Label");//  ID  ：XXX
        this.ip = this.userNode.getChildByName("ip").getComponent("cc.Label");//  IP  ：XXX
        this.btnMask = this.node.getChildByName("btnMask");
    },

    initPart2:function(){
        this.btnKick = this.node.getChildByName("btnKick");
        this.btnKick.active = true;
    },

    setUserInfo:function(nick,uid,ip){
        console.log("setUserInfo@@@@@@@@@@@")
        this.nickName.string = "昵称："+nick;
        this.id.string = "  ID  ："+uid;
        if(ip)
            this.ip.string = "  IP  ："+ip;
        else
            this.ip.string = "";
    },

    setMainHeadFrame:function(){
        if(confige.meWXHeadFrame != -1)
            this.head.spriteFrame = confige.meWXHeadFrame;
    },

    setHeadFrameWithURL:function(url){
        window.DKTools.setFrameWithUrl(url,this.head);
    },

    btnFaceClick:function(event, customEventData){
        var index = parseInt(customEventData);
        if(this.selectHead != -1)
            pomelo.clientSend("say",{"msg": {"sayType":100, "chairBegin":gameData.gameMainScene.meChair, "chairEnd":this.selectHead,"index":index,"sex":confige.curSex}});
        this.hideLayer();
    },

    btnKickChair:function(){
        pomelo.request("connector.entryHandler.sendFrame", {"code" : "kickChair","params":{chair:this.selectHead}}, function(data) {
            console.log("kick user");
            console.log(data);
        });
        this.hideLayer();
    },

    showLayer:function(isMe){
        if(this.isInit == false)
            this.onInit();
        this.node.active = true;
        if(isMe === true)
            this.btnMask.active = true;
        if(isMe === false)
            this.btnMask.active = false;
    },

    hideLayer:function(){
        this.node.active = false;
    },
});
